<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>逾期催收列表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
    <script type="text/javascript" src="//cdn.staticfile.org/webuploader/0.1.5/webuploader.min.js" charset="utf-8"></script>
    <script src="<%=path%>/resource/lib/plugins/ajaxfileupload.js" type="text/javascript"></script>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>应收总金额合计(元): </b><span id="arAmt"/></td>
                    <td><b>逾期金额合计(元): </b><span id="ovdAmt"/></td>
                    <td><b>罚息金额合计(元): </b><span id="fineAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
            <div id="ligergrid1" class="sq-grid"></div>
            <div id="prjFileInfoCfgGrid" class="sq-grid"></div>
            <table id="explain" border="1" cellspacing="0" cellpadding="0" width="100%" style="border:solid #ECECEC; border-width:1px 0px 0px 1px;">
                <tr>
                    <td border:solid #ECECEC; border-width:0px 1px 1px 0px; padding-left:10px;><p>补充说明</p></td>
                    <td width="80%" border:solid #ECECEC; border-width:0px 1px 1px 0px; padding-left:10px;><textarea cols="170" rows="6" id="ulRem">${UlRem}</textarea></td>
                </tr>
            </table>
            <div class="btnsBox formBtns "  style="text-align:center">
                <c:if test="${flag==2}">
                    <span id="addBtn" class="sq-button sq-button-round fileupload-button" onclick="updateRskUlFileLog(${fsId});">保存</span>
                </c:if>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var contractGrid = null, fsId = ${fsId}, flag = ${flag}, prjId = ${prjId};
    $(function () {
        var url = '<%=path%>/risk/overdueCollect/getPrjAndContractList.do?prjId=' + prjId;
        contractGrid = $("#ligergrid1").ligerGrid({
            url: url,
            method: 'get',
            columns: [
                {
                    display: '事业部', name: 'buOrgCd', width: 120
                },
                {
                    display: '合同号', name: 'lsCntNo', width: 160, render: function (rowdata) {
                        if (rowdata.tableName == "PRJ_PRD_PAY_SCH_M" || rowdata.tableName == "MCR_BILL_M") {
                            return '<a style="cursor: pointer;" onclick="contractLink(' + rowdata.prjId + ',\'' + rowdata.tableName + '\');">' + rowdata.lsCntNo + '</a> ';
                        } else {
                            return rowdata.lsCntNo;
                        }
                    }
                },
                {
                    display: '客户名称', name: 'cstNm', width: 120
                },
                {display: '逾期期次', name: 'minPayPd', width: 150, enabledSort: true},
                {display: '逾期日期', name: 'minOverdueDate', minWidth: 100, enabledSort: true, render: renderDate},
                {display: '逾期天数', name: 'ovdDays', width: 120,},
                {
                    display: '应收金额', name: 'arAmt', width: 120, align: 'left',
                    render: function (rowdata, index, value) {
                        return '<a style="cursor: pointer;" onclick="overduePaySchDPRJ(' + rowdata.prjId + ',' + rowdata.arAmt + ',' + rowdata.ovdAmt + ',' + rowdata.fineAmt + ');">&yen;' + FormatMoney(rowdata.arAmt / 100) + '</a> ';
                    }
                },
                {
                    display: '逾期金额', name: 'ovdAmt', width: 120, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额', name: 'findAmt', width: 120, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $(".l-grid-row-cell-detailbtn").trigger('click');
            },
            detail: {
                height: 'auto',
                onShowDetail: showPaySchGrid
            }
        });
        getOvdAmtSummary();
    });

    // 更新补充说明
    function updateRskUlFileLog(fsId) {
        var ulRem = $('#ulRem').val();
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: {'fsId': fsId, 'ulRem': ulRem},
            url: '<%=path%>/risk/overdueCollect/updateRskUlFileLog.do',
            success: function (msg) {
                if ('1' == msg.success) {
                    $.ligerDialog.SQalert({content:"修改成功！", SQ_type: "success"});
                } else {
                    $.ligerDialog.SQalert({content:"修改失败！", SQ_type: "error"});
                }
            }
        });
    }

    // 客户详情页面
    function showDetail(_id) {
        parent.parent.mainApp.f_addTab('tab_customer_np_detail' + _id, '客户详情', '<%=path%>/customer/cstbscinfo/showDetail.do?id=' + _id);
    }

    //查询汇总
    function getOvdAmtSummary() {
        var data = {"prjId": prjId};
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: data,
            url: '<%=path%>/risk/overdueCollect/getSum4FileSup.do',
            success: function (msg) {
                $("#arAmt").text(FormatMoney(msg.arAmt / 100));
                $("#ovdAmt").text(FormatMoney(msg.ovdAmt / 100));
                $("#fineAmt").text(FormatMoney(msg.fineAmt / 100));
            }
        });
    }

    /* 还款明细 */
    function repaymentDtl(cstId, cstNm) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '还款明细',
            url: '<%=path%>/risk/overdueCollect/toCstCapFundListPage.do?cstId=' + cstId + "&cstNm=" + cstNm,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    /* 逾期明细 */
    function overdueDtl(cstId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 850,
            height: 500,
            title: '逾期明细',
            url: '<%=path%>/capital/capOverdueInfo/toOverdueDtl.do?cstId=' + cstId,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }


    function contractLink(prjId, tableName) {
        if (tableName) {
            if (tableName == 'PRJ_PRD_PAY_SCH_M') {//融资租赁
                Add_navTab('tab_project_detail' + prjId, '项目详情', '<%=path%>/project/prjbscinfo/toModifyPage.do?fromPrjFlag=true&&id=' + prjId + '&&detailFlag=true');
            } else if (tableName == "MCR_BILL_M") { //小贷
                Add_navTab('MCR_BILL_M_' + prjId, '小贷账单详情', "<%=path%>/mcr/mcrBillM/toBillDtlPage.do?id=" + prjId);
            }
        }
    }

    /**
     * 显示某个合同下面的支付表 grid
     * @param row
     * @param detailPanel
     * @param callback
     */
    function showPaySchGrid(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        var url = '<%=path%>/risk/overdueCollect/getOverduePaySchList4FileSup.do?prjId=' + row.prjId
        contractGrid = $(gridBox).ligerGrid({
            url: url,
            method: 'get',
            columns: [
                {
                    display: '支付表号', name: 'paySchNo', width: 200, render: function (rowdata) {
                        var tableName = rowdata.tableName;
                        if (tableName == "PRJ_PRD_PAY_SCH_M") {
                            return '<a style="cursor: pointer;" onclick="paySchLink(' + rowdata.paySchId + ',\'' + rowdata.tableName + '\',' + rowdata.prjId + ',' + rowdata.prjPrdDtlId + ');">' + rowdata.paySchNo + '</a> ';
                        } else {
                            return rowdata.paySchNo;
                        }
                    }
                },
                {display: '支付表状态', name: 'prdStsCd', width: 160},
                {display: '逾期期次', name: 'payPd', width: 150, enabledSort: true},
                {display: '逾期日期', name: 'overdueDate', minWidth: 100, enabledSort: true, render: renderDate},
                {display: '逾期天数', name: 'overdueDay', width: 120,},
                {display: '最高逾期天数', name: 'ovdMaxDay', width: 120,},
                {
                    display: '应收金额', name: 'arAmt', width: 120, align: 'left',
                    render: function (rowdata, index, value) {
                        return '<a style="cursor: pointer;" onclick="overduePaySchDPAY(' + rowdata.paySchId + ',' + rowdata.arAmt + ',' + rowdata.ovdAmt + ',' + rowdata.fineAmt + ');">&yen;' + FormatMoney(rowdata.arAmt / 100) + '</a> ';
                    }
                },
                {
                    display: '逾期金额', name: 'ovdAmt', width: 120, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额', name: 'fineAmt', width: 120, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                },
                {
                    display: '结清价', name: 'prdStsCd', width: 160,
                    render: function (rowdata, index, value) {
                        return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="clearingPriceDetail(' + rowdata.paySchId + ',' + rowdata.arAmt + ',' + rowdata.ovdAmt + ',' + rowdata.fineAmt + ',\'' + rowdata.tableName + '\',' + rowdata.overdueDay + ');">查看结清价</a>  ';
                    }
                },
                {
                    display: '操作', name: 'caozuo', width: 160,
                    render: function (rowdata, index, value) {
                        var tableName = rowdata.tableName;
                        if (tableName == "PRJ_PRD_PAY_SCH_M") {
                            return '<a class="sq-button-hasicon" style="cursor: pointer;" onclick="carDetail(' + rowdata.paySchId + ');"><i class="sqBtnIco_49"></i>车辆详情</a>  ';
                        } else {
                            return "";
                        }
                    }
                }

            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false,
        });
    }

    function paySchLink(paySchId, tableName, prjId, prjPrdDtlId) {
        if (tableName) {
            // WTF
            if (tableName == "PRJ_PRD_PAY_SCH_M") { //融资租赁
                Add_navTab('tab_prj_quat_prps' + paySchId, '查看支付表', '<%=path%>/project/prjprdpayschm/toDetailPage.do?id=' + paySchId);
            }
        }
    }

    function carDetail(paySchId) {
        parent.parent.mainApp.f_addTab('tab_oberdue_cardetail', '车辆详情', '<%=path%>/risk/overdueCollect/carDetail.do?paySchId=' + paySchId);
    }


    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //查看支付表明细
    function showPaySchDetail(paySchId) {
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/risk/ovdCollect/getPayInfo.do?paySchId=' + paySchId,
            success: function (msg) {
                if (msg.success == 1) {
                    Add_navTab('tab_prj_quat_prps' + paySchId, '查看支付表', '<%=path%>/project/prjprdpayschm/toAddPage.do?prjId=' + msg.data.prjId + '&&id=' + paySchId + '&&prjPrdDtlId=' + msg.data.prjPrdDtlId + '&&prjPrdId=' + msg.data.prjPrdId + '&&detailFlag=true');
                }
            }
        });
    }

    /**
     * 点击用户应收金额
     */
    function overduePaySchDCST(cstid, arAmt, ovdAmt, fineAmt) {
        overduePaySchD(cstid, '', '', arAmt, ovdAmt, fineAmt);
    }

    /**
     * 点击项目应收金额
     * @param prjId
     */
    function overduePaySchDPRJ(prjId, arAmt, ovdAmt, fineAmt) {
        overduePaySchD('', prjId, '', arAmt, ovdAmt, fineAmt);

    }

    /**
     * 点击支付表应收金额
     */
    function overduePaySchDPAY(paySchId, arAmt, ovdAmt, fineAmt) {
        overduePaySchD('', '', paySchId, arAmt, ovdAmt, fineAmt)
    }

    function overduePaySchD(cstId, prjId, paySchId, arAmt, ovdAmt, fineAmt) {
        parent.parent.mainApp.f_addTab('tab_overdue_payschd', '应收金额', '<%=path%>/risk/overdueCollect/toOverduePaySchDList.do?cstId=' + cstId + '&prjId=' + prjId + '&paySchId=' + paySchId + '&arAmt=' + arAmt + '&ovdAmt=' + ovdAmt + '&fineAmt=' + fineAmt);
    }

    //查看结清价
    function clearingPriceDetail(paySchId, arAmt, ovdAmt, fineAmt, tableNm, overdueDay) {
        parent.parent.mainApp.f_addTab('tab_overdue_clearingprice', '结清详情', '<%=path%>/risk/overdueCollect/toOverdueClearingPrice.do?paySchId=' + paySchId + '&arAmt=' + arAmt + '&ovdAmt=' + ovdAmt + '&fineAmt=' + fineAmt + '&tableNm=' + tableNm + '&overdueDay=' + overdueDay);
    }

    var prjFileInfoCfgGrid = null;//项目资料配置明细

    var prjTrigonalCstVideoUpload;

    $(function () {
        prjTrigonalCstVideoUpload = makeUploaders("prjTrigonalCstVideoInfoCfgGrid", 2);
        //贷后补充项目资料Grid
        prjFileInfoCfgGrid = $("#prjFileInfoCfgGrid").ligerGrid({
            url: '<%=path%>/risk/overdueCollect/initSupplementList.do?cstMgrOrgCd=${cstMgrOrgCd}&rskFileId=' + fsId + '&prjTypCd=${prjTypCd}',
            method: 'get',
            columns: [
                {display: '资料名称', name: 'datNm', align: 'left', minWidth: 100, enabledSort: false},
                {
                    display: '上传文件名称', name: 'fileNm', minWidth: 100, enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        if (value) {
                            var h;
                            h = '<a href="javascript:uploadFileByUrl(';
                            h += "'" + rowdata.filePath + "'";
                            h += ",'" + rowdata.fileNm + "'";
                            h += ')">' + rowdata.fileNm + '</a>'
                            return h;
                        }
                    }
                },
                {display: '上传时间', name: 'crtTm', align: 'left', minWidth: 100, enabledSort: false, render: renderDate},
                {display: '状态', name: 'audStsCdNm', width: 100, enabledSort: false},
                {
                    display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (flag == 2) {
                            if (rowdata.fileId && rowdata.audStsCd != 1) {
                                <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjFile" pInstId="${pInstId}">
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="delFile(event,' + rowdata.fileId + ');"><i class="sqBtnIco_7"></i>删除</a>';
                                </sys:FlowFrmAth>
                            }
                        } else if (flag == 1) {
                            if (rowdata.filePath) {
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',1);"><i class="sqBtnIco_15"></i>验证通过</a>';
                                h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="modifyAudStsCd(event,' + rowdata.fileId + ',2);"><i class="sqBtnIco_14"></i>验证不通过</a>';
                            }
                        }
                        return h;
                    }
                },
                {
                    display: '上传', name: 'uploadNm', width: 80, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '';
                        if (flag == 2) {
                            <sys:FlowFrmAth preTaskIds="${preTaskIds}" athCd="addPrjFile" pInstId="${pInstId}">
                            h += '<span class="sq-button sq-button-round fileupload-button">上传<input type="file" id="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '" multiple name="fileup_' + rowdata.cfgCd + '_' + rowdata.cfgDtlCd + '"' +
                                ' class="fileupload-input" onchange="onChangefile_multi(event,\'' + rowdata.cfgCd + '\',\'' + rowdata.cfgDtlCd + '\',\'' + rowdata.orgCd + '\',2)"></span>';
                            </sys:FlowFrmAth>
                        }
                        return h;
                    }
                },
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            isScroll: false,
            rownumbers: false,  //显示序号
            checkbox: false,
            allowUnSelectRow: false,
            alternatingRow: false,
            frozen: false,
            usePager: false,
            onAfterShowData: function () {
                $('#prjFileInfoCfgGrid').rowspan('datNm');
                $('#prjFileInfoCfgGrid').rowspan('uploadNm');
            },
        });

        $("#pageloading").hide();
    });

    function onChangefile_multi(e, cfgCd, cfgDtlCd, orgCd, typ) {
        var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
        var filePath = "";
        if (typ == 1) {
            filePath = "customer";
        } else if (typ == 2) {
            filePath = "prjFileInfo";
        }

        $.ajaxFileUpload({
            url: '<%=path%>/system/sysulfilesrec/upload.do',
            secureuri: false,
            fileElementId: e.target.id,  //这里不在是以前的id了，要写成数组的形式！
            dataType: 'json',
            data: {filePath: filePath},
            success: function (msg) {
                if (msg.success == 1) {
                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        data: {
                            'fileParams': JSON.stringify(msg.data),
                            'rskFileId':fsId,
                            'cfgCd': cfgCd,
                            'cfgDtlCd': cfgDtlCd,
                            'orgCd': orgCd
                        },
                        url: '<%=path%>/risknew/rskulfilelog/ulSuppFile.do',
                        success: function (msg) {
                            if (msg.success == 1) {
                                prjFileInfoCfgGrid.reload();
                            } else {
                                $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                            }
                            $.ligerDialog.hide();
                        }
                    });
                } else {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    };

    $(function () {
        $(document).on('click', 'a[name=showimg]', function () {
            event.preventDefault();
            var href = $(this).attr('href');
            reg = new RegExp('^.*\.(?:png|jpg|bmp|gif|jpeg|PNG|JPG|BMP|GIF|JPEG)$');
            if (reg.test(href)) {
                SQ.imgPreview(href);
            } else {
                window.open(href);
            }
        });
    });

    var pInstId = $("#pInstId").val();
    var preTaskIds = $("#preTaskIds").val();
    var flowParms = "&&pInstId=" + pInstId + "&&preTaskIds=" + preTaskIds;

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    var reloadChildGridId = null;
    var callbackFlag = 3;

    //上传项目文件
    function upFileForPrj(event, _cfgCd, _cfgDtlCd, _orgCd) {
        //获取子GridID
        event.stopPropagation();
        reloadChildGridId = $(event.target).parents('.sq-grid').attr('ligeruiid');

        callbackFlag = 2;
        $("#cfgCd").val(_cfgCd);
        $("#cfgDtlCd").val(_cfgDtlCd);
        $("#orgCd").val(_orgCd);
        $.ligerDialog.SQopen({
            width: 400,
            height: 100,
            title: '资料上传',
            target: $("#prj_file_div"),
        });
    }

    //上传项目文件回调方法
    function uploadCallback(_data) {
        if (callbackFlag == 2) {
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {
                    'fileParams': JSON.stringify(_data),
                    'rskFileId':fsId,
                    'cfgCd': $("#cfgCd").val(),
                    'cfgDtlCd': $("#cfgDtlCd").val(),
                    'orgCd': $("#orgCd").val()
                },
                url: '<%=path%>/risknew/rskulfilelog/ulSuppFile.do',
                success: function (msg) {
                    if (msg.success == 1) {
                        parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                        if (reloadChildGridId) liger.get(reloadChildGridId).reload();
                    } else {
                        $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                    }
                    $.ligerDialog.hide();
                }
            });
        }
    }

    //删除文件
    function delFile(event, _fileId) {
        top.$.ligerDialog.confirm("确认删除吗?", function (flag) {
            if (!flag) {
                return;
            } else {
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {'fileId': _fileId},
                    url: '<%=path%>/project/prjFileInfo/removeFile.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            parent.$('li[tabid="mateTab"] a').text('项目资料(' + msg.data + ')');
                            event.stopPropagation();
                            var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                            liger.get(gridID).reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            }
        });
    }

    //修改资料的验证状态
    function modifyAudStsCd(event, _fileId, _audStsCd) {
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'fileId': _fileId, 'audStsCd': _audStsCd},
            url: '<%=path%>/project/prjFileInfo/modifyFileAudStsCd.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    event.stopPropagation();
                    var gridID = $(event.target).parents('.sq-grid').attr('ligeruiid');
                    liger.get(gridID).reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }

    function downFile(_url) {
        window.open(_url);
    }

    function uploadFileByUrl(_url, _name) {
        if (SQ.regs.img.test(_name)) {
            //SQ.imgPreview(_url);
            //SQ.imgPreview(_url, true);
            window.__ImgSrc = _url;
            window.__ImgTit = _name;
            window.open('<%=path%>/project/prjbscinfo/imgWinOpen.do', '', 'location=yes, width=800, height=600');
        } else {
            window.open(_url);
        }
    }

    var opts = {cfgCd: "", cfgDtlCd: "", orgCd: ""};

    function makeUploaders(gridNm, typ) {
        var filePath = "";
        if (typ == 1) {
            filePath = "/customer/";
        } else if (typ == 2) {
            filePath = "/prjFileInfo/";
        }
        var userInfo = {userId: "${currentUsrId}", md5: "", filePath: filePath};
        var chunkSize = 5000 * 1024;        //分块大小
        var originFileName = null;          //原始文件名称
        var uniqueFileName = null;          //文件唯一标识符
        var fileExt = null;
        var md5Mark = null;

        var backEndUrl = '<%=path%>/system/sysulfilesrec/tillFileUpload.do';
        var backStatusUrl = '<%=path%>/system/sysulfilesrec/tillFileUploadStatus.do';
        var uploader = WebUploader.create({
            swf: "Uploader.swf"
            , server: backEndUrl
            , resize: false
            , compress: false
            , prepareNextFile: true
            , chunked: true
            , chunkSize: chunkSize
            , threads: 3
            , formData: $.extend(true, {}, userInfo)
            , fileNumLimit: 1
            //, fileSingleSizeLimit: 1000 * 1024 * 1024
            , duplicate: true
        });
        uploader.on("fileQueued", function (file) {
            var selectedRowId = file.source._refer.parents('.l-grid-row').attr('id');
            var rowId = selectedRowId.slice(selectedRowId.lastIndexOf("|") + 1);
            var rowData = liger.get(gridNm).getRow(rowId);
            opts = {cfgCd: rowData.cfgCd, cfgDtlCd: rowData.cfgDtlCd, orgCd: rowData.orgCd};
            var wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            uploader.upload();
        });
        uploader.on("uploadStart", function (file) {
            originFileName = file.name;
            fileExt = file.ext;
            uniqueFileName = md5('' + userInfo.userId + file.name + file.type + file.lastModifiedDate + file.size + new Date().getTime());
            md5Mark = uniqueFileName;
            userInfo.md5 = uniqueFileName;
        });
        uploader.on('uploadBeforeSend', function (block, data, headers) {
            // 修改data可以控制发送哪些携带数据。
            data.originFileName = originFileName;
            data.fileName = uniqueFileName;
            data.ext = fileExt;
            //分片验证是否已传过，用于断点续传
            var task = new $.Deferred();
            $.ajax({
                type: "POST"
                , url: backStatusUrl
                , data: {
                    status: "chunkCheck"
                    , originFileName: originFileName
                    , fileName: uniqueFileName
                    , chunkIndex: block.chunk
                    , size: block.end - block.start
                    , filePath: filePath
                }
                , cache: false
                , timeout: 5000 //todo 超时的话，只能认为该分片未上传过
                , dataType: "json"
            }).then(function (data, textStatus, jqXHR) {
                if (data.success == 2) {   //若存在，返回失败给WebUploader，表明该分块不需要上传
                    task.resolve();
                } else {
                    task.reject();
                }
            }, function (jqXHR, textStatus, errorThrown) {    //任何形式的验证失败，都触发重新上传
                task.resolve();
            });
            return $.when(task);
        });
        uploader.on("uploadComplete", function (file) {
            var chunksTotal = 0;
            if ((chunksTotal = Math.ceil(file.size / chunkSize)) > 1) {
                //合并请求
                var task = new $.Deferred();
                $.ajax({
                    type: "POST"
                    , url: backStatusUrl
                    , data: {
                        status: "chunksMerge"
                        , originFileName: originFileName
                        , fileName: uniqueFileName
                        , chunks: chunksTotal
                        , ext: file.ext
                        , md5: md5Mark
                        , filePath: filePath
                    }
                    , cache: false
                    , dataType: "json"
                }).then(function (data, textStatus, jqXHR) {
                    task.resolve();
                    if (data.success == 1 && Math.ceil(file.size / chunkSize) > 1) {
                        $.ajax({
                            type: 'post',
                            dataType: 'json',
                            data: {
                                'fileParams': JSON.stringify(data.data),
                                'rskFileId':fsId,
                                'cfgCd': opts.cfgCd,
                                'cfgDtlCd': opts.cfgDtlCd,
                                'orgCd': opts.orgCd
                            },
                            url: '<%=path%>/risknew/rskulfilelog/ulSuppFile.do',
                            success: function (msg) {
                                if (msg.success == 1) {
                                    prjTrigonalCstVideoInfoCfgGrid.reload();
                                } else {
                                    $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                                }
                                $.ligerDialog.hide();
                            }
                        });
                    } else if (data.success != 1) {
                        //wait_dialog.close();
                        $.ligerDialog.SQalert({content: data.info, SQ_type: "error"});
                    }
                    uploader.removeFile(file);//上传成功后移除队列文件
                }, function (jqXHR, textStatus, errorThrown) {
                    task.reject();
                });
                uploader.removeFile(file);//上传成功后移除队列文件
                return $.when(task);
            } else {
                uploader.removeFile(file);//上传成功后移除队列文件
            }
        });
        uploader.on('uploadAccept', function (obj, ret) {
            if (ret.success == 1 && Math.ceil(obj.file.size / chunkSize) <= 1) {
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {
                        'fileParams': JSON.stringify(ret.data),
                        'rskFileId':fsId,
                        'cfgCd': opts.cfgCd,
                        'cfgDtlCd': opts.cfgDtlCd,
                        'orgCd': opts.orgCd
                    },
                    url: '<%=path%>/risknew/rskulfilelog/ulSuppFile.do',
                    success: function (msg) {
                        if (msg.success == 1) {
                            prjTrigonalCstVideoInfoCfgGrid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: "资料上传超时", SQ_type: "error"});
                        }
                        $.ligerDialog.hide();
                    }
                });
            }
        });
        return uploader;
    }

    function saveFlow(id) {
        $("#addBtn").attr("style", "display:none;");
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {'id': id, 'paySchNo': '${prjFilesRecVO.paySchNo}'},
            url: '<%=path%>/risk/overdueCollect/saveFlow.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                if (msg.success == 1) {
                    alert(msg.info);
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    Remove_navTab();//新增，关闭当前页面

                } else {
                    alert(msg.info);
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});

                }
                $.ligerDialog.hide();
            }
        });
    }

    function close() {
        $("#l-dialog-table").hide();
    }

</script>

</body>
</html>
